#include "stm32f4xx.h"                  // Device header
#include "DAC.h"

void MY_DAC_Init(){
	// ADC1 clock
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC,ENABLE);
	
	// PA5 for AIN
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
	GPIO_Init(GPIOA, &GPIO_InitStructure);
	
	DAC_InitTypeDef DAC_InitTypeStruct;
	DAC_InitTypeStruct.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0;
	DAC_InitTypeStruct.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
	DAC_InitTypeStruct.DAC_Trigger = DAC_Trigger_None;
	DAC_InitTypeStruct.DAC_WaveGeneration =  DAC_WaveGeneration_None;
	DAC_Init(DAC_Channel_1,&DAC_InitTypeStruct);
	DAC_Cmd(DAC_Channel_1,ENABLE);
	
	DAC_SetChannel1Data(DAC_Align_12b_R,4090); // 1.7v
	
}
